package com.baymax.study.base.enum_impl;

import org.reflections.Reflections;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.Set;

public class EnumImplTestClient {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {

//        ApplicationContext context = new AnnotationConfigApplicationContext(ScanConfig.class);
//        Map<String, MessageTopicI> beans = context.getBeansOfType(MessageTopicI.class);
//        beans.forEach((name, topic) -> {
//            System.out.println(topic.getValue());
//        });

        Reflections reflections = new Reflections("com.baymax.study");
        Set<Class<? extends MessageTopicI>> classSet = reflections.getSubTypesOf(MessageTopicI.class);
        for (Class<? extends MessageTopicI> enumClass : classSet) {
            if (enumClass.isEnum()) {
                Enum[] enumConstants = (Enum[]) enumClass.getEnumConstants();
                for (Enum anEnum : enumConstants) {
                    if (anEnum instanceof MessageTopicI) {
                        MessageTopicI messageTopicI = (MessageTopicI) anEnum;
                        System.out.println(messageTopicI.getValue());
                    }
                }
            }
        }


    }

    @ComponentScan("com.baymax.study.enum_impl")
    @EnableAspectJAutoProxy
    static class ScanConfig {
    }
}
